package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.commons.utile.BeanCopyUtil;
import com.woniuxy.controller.dto.GetGuidanceDto;
import com.woniuxy.controller.form.GetGuidanceForm;
import com.woniuxy.dao.model.RepairGuidance2;
import com.woniuxy.dao.RepairGuidance2Dao;
import com.woniuxy.service.RepairGuidance2Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务指南 服务实现类
 * </p>
 *
 * @author Keep it simple
 * @since 2022-06-28
 */
@Service
public class RepairGuidance2ServiceImpl extends ServiceImpl<RepairGuidance2Dao, RepairGuidance2> implements RepairGuidance2Service {

    @Resource
    private RepairGuidance2Dao repairGuidance2Dao ;


    /**
     * 获取服务指南（通过大标题ID）
     * @param getGuidanceForm
     * @return
     */
    @Override
    public Page<GetGuidanceDto> getGuidance(GetGuidanceForm getGuidanceForm) {
        QueryWrapper<RepairGuidance2> wrapper = new QueryWrapper<>();
        wrapper.eq("deleted", 1);
        wrapper.eq("large_headline_id", getGuidanceForm.getGuidanceId());
        wrapper.orderByDesc("publishDate");
        Page<RepairGuidance2> page = repairGuidance2Dao.selectPage(new Page<RepairGuidance2>(getGuidanceForm.getPageNum(), getGuidanceForm.getPageSize()), wrapper);
        Page<GetGuidanceDto> getGuidanceDtoPage = BeanCopyUtil.copyPages(page, GetGuidanceDto.class);
        System.out.println(getGuidanceDtoPage);
        return getGuidanceDtoPage;
    }
}
